import type { ColumnType } from 'ant-design-vue/es/table/interface';

type Type = 'image' | 'user';

// 使用泛型参数 T 表示数据记录类型
interface Params<T> extends ColumnType<T> {
  type?: Type;
  renderField?: keyof T; // 确保 renderField 是 T 的属性
}

export const genColumn = <T extends Record<string, any>>(params: Params<T>): ColumnType<T> => {
  const { type, renderField, ...column } = params;

  const typeMap = {
    image: {
      ...column,
      customRender: ({ record }: { record: T & { path: string } }) => record.path,
    },
    user: {
      ...column,
      customRender: ({ record }: { record: T & { name: string } }) => record.name,
    },
  };

  return type ? (typeMap[type] as ColumnType) : column;
};
